package com.dycx.api.controller.manage.food;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.food.dto.OrderCreateDTO;
import com.dycx.food.dto.OrderDTO;
import com.dycx.food.dto.OrderGoodsDTO;
import com.dycx.food.service.OrderFoodService;
import com.dycx.food.service.OrderGoodsFoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "/manage/food/order")
public class OrderFoodController {

    @Resource
    private OrderFoodService orderService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_ORDER, bizValue = "{#orderCreateDto.orderNo}")
    @PostMapping("/createOrder")
    public RestResponse<?> createOrder(@RequestBody @Valid OrderCreateDTO orderCreateDto) {
        return RestResponse.success(orderService.createOrder(orderCreateDto));
    }

    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody OrderDTO orderDto) {
        return RestResponse.success(orderService.getPage(orderDto));
    }


    /**
     * 根据订单号查询订单信息
     **/
    @GetMapping("/getOrderDetailByOrderNo")
    public RestResponse<?> getOrderDetailByOrderNo(String orderNo) {
        return RestResponse.success(orderService.getOrderDetailByOrderNo(orderNo, true, true));
    }

    /**
     * 取消订单
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_ORDER, bizValue = "{#orderNo}")
    @GetMapping("/cancelOrder")
    public RestResponse<?> cancelOrder(String orderNo) {
        return orderService.cancelOrder(orderNo) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 完成订单
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_ORDER, bizValue = "{#orderNo}")
    @GetMapping("/completeOrder")
    public RestResponse<?> completeOrder(String orderNo) {
        return orderService.completeOrder(orderNo) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改备注
     **/
    @WriterLog(bizType = BizTypeEnum.MALL_ORDER, bizValue = "{#orderDTO.orderNo}")
    @PostMapping("/updateServiceRemark")
    public RestResponse<?> updateServiceRemark(@RequestBody OrderDTO orderDTO) {
        return orderService.updateServiceRemark(orderDTO) ? RestResponse.success() : RestResponse.fail();
    }
}
